home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / misc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  2.8 KB  |  114 lines

  1. #ifndef H_MISC
  2. #define H_MISC
  3.  
  4. /**
  5.  * \file lib/misc.h
  6.  *
  7.  */
  8.  
  9. #include <string.h>
  10.  
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14.  
  15. /**
  16.  * Create directory if it does not exist, and make sure path is writable.
  17.  * @note This will only create last component of directory path.
  18.  * @param dpath        directory path
  19.  * @param dname        directory use string
  20.  * @return        rpmRC return code
  21.  */
  22. rpmRC rpmMkdirPath (const char * dpath, const char * dname)
  23.     /*@globals h_errno, fileSystem, internalState @*/
  24.     /*@modifies fileSystem, internalState @*/;
  25.  
  26. /**
  27.  * Split string into fields separated by a character.
  28.  * @param str        string
  29.  * @param length    length of string
  30.  * @param sep        separator character
  31.  * @return        (malloc'd) argv array
  32.  */
  33. /*@only@*/ char ** splitString(const char * str, int length, char sep)
  34.     /*@*/;
  35.  
  36. /**
  37.  * Free split string argv array.
  38.  * @param list        argv array
  39.  */
  40. void freeSplitString( /*@only@*/ char ** list)
  41.     /*@modifies list @*/;
  42.  
  43. /**
  44.  * Remove occurences of trailing character from string.
  45.  * @param s        string
  46.  * @param c        character to strip
  47.  * @return         string
  48.  */
  49. /*@unused@*/ static inline
  50. /*@only@*/ char * stripTrailingChar(/*@only@*/ char * s, char c)
  51.     /*@modifies *s */
  52. {
  53.     char * t;
  54. /*@-boundswrite@*/
  55.     for (t = s + strlen(s) - 1; *t == c && t >= s; t--)
  56.     *t = '\0';
  57. /*@=boundswrite@*/
  58.     return s;
  59. }
  60.  
  61. /**
  62.  * Like the libc function, but malloc()'s the space needed.
  63.  * @param name        variable name
  64.  * @param value        variable value
  65.  * @param overwrite    should an existing variable be changed?
  66.  * @return        0 on success
  67.  */
  68. int dosetenv(const char * name, const char * value, int overwrite)
  69.     /*@globals environ@*/
  70.     /*@modifies *environ @*/;
  71.  
  72. /**
  73.  * Like the libc function, but malloc()'s the space needed.
  74.  * @param str        "name=value" string
  75.  * @return        0 on success
  76.  */
  77. int doputenv(const char * str)
  78.     /*@globals environ@*/
  79.     /*@modifies *environ @*/;
  80.  
  81. /**
  82.  * Return file handle for a temporaray file.
  83.  * A unique temporaray file path will be generated using
  84.  *    rpmGenPath(prefix, "%{_tmppath}/", "rpm-tmp.XXXXX")
  85.  * where "XXXXXX" is filled in using rand(3). The file is opened, and
  86.  * the link count and (dev,ino) location are verified after opening.
  87.  * The file name and the open file handle are returned.
  88.  *
  89.  * @param prefix    leading part of temp file path
  90.  * @retval fnptr    temp file name (or NULL)
  91.  * @retval fdptr    temp file handle
  92.  * @return        0 on success
  93.  */
  94. int makeTempFile(/*@null@*/ const char * prefix,
  95.         /*@null@*/ /*@out@*/ const char ** fnptr,
  96.         /*@out@*/ FD_t * fdptr)
  97.     /*@globals rpmGlobalMacroContext, h_errno,
  98.         fileSystem, internalState @*/
  99.     /*@modifies *fnptr, *fdptr, rpmGlobalMacroContext,
  100.         fileSystem, internalState @*/;
  101.  
  102. /**
  103.  * Return (malloc'd) current working directory.
  104.  * @return        current working directory (malloc'ed)
  105.  */
  106. /*@only@*/ char * currentDirectory(void)
  107.     /*@*/;
  108.  
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112.  
  113. #endif    /* H_MISC */
  114.